/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hcsc.datapower.CMDB.service;

import com.hcsc.datapower.CMDB.dao.DomainDao;
import com.hcsc.datapower.CMDB.dao.ServiceDao;
import com.hcsc.datapower.CMDB.daoImpl.UtilDaoImpl;
import com.hcsc.datapower.CMDB.gui.ConfigurationWindow;
import com.hcsc.datapower.CMDB.integration.Domain;
import com.hcsc.datapower.CMDB.integration.ServiceInformation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
/**
 *
 * @author I307211
 */
public class ConfigurationWindowController {
    
    UtilDaoImpl utilDao;
    DomainDao domainDao;
    ServiceDao serviceDao;
    
    ConfigurationWindow configurationWindow;
    
    
    private static String PLATFORM_CURRENT = "";
    private static String DOMAIN_CURRENT = "";
    private static String SERVICE_CURRENT = "";
    
    
    public ConfigurationWindowController(){
    
    }
    
    public void loadPlatforms(){
        ArrayList<String> tmp = (ArrayList<String>) utilDao.getPlatforms();
        
        if(tmp == null || tmp.isEmpty()){
            //throw exception
                return;
        }
        
        
        Iterator itr = tmp.iterator();
        while(itr.hasNext()){
           getConfigurationWindow().setPlatforms((String)itr.next());
        }
    }
    
    public void loadDomains(String platform){
        
        //if(!PLATFORM_CURRENT.equalsIgnoreCase("") && PLATFORM_CURRENT.equalsIgnoreCase(platform)){
          //  return;
        //}else{
            
            getConfigurationWindow().clearDomains();
            List<Domain> tmp = domainDao.getDomainsByPlatform(platform);

            if(tmp == null || tmp.isEmpty()){
                //throw exception...
                getConfigurationWindow().setDomains(new String("No Domains"));
                return;
            }
            Iterator itr = tmp.iterator();
            while(itr.hasNext()){
                getConfigurationWindow().setDomains( ((Domain)itr.next()).getDomain_name() );
            }
          //  PLATFORM_CURRENT = platform;
        //}
    }
    
    public void loadServices(String platform, String domain){
        
       
        getConfigurationWindow().clearServices();
        List<ServiceInformation> tmp = serviceDao.getServices(platform, domain);
        
        if(tmp == null || tmp.isEmpty()){
            //throw exception...
            getConfigurationWindow().setServices(new String("No Services"));
            return;
        }
        Iterator itr = tmp.iterator();
        while(itr.hasNext()){
            getConfigurationWindow().setServices(((ServiceInformation)itr.next()).getService() );
        }
    }
    
    public void loadServiceInformation(String env, String domain, String service){
        //init service detail window
    }

    public UtilDaoImpl getUtilDao() {
        return utilDao;
    }

    @Autowired
    public void setUtilDao(UtilDaoImpl utilDao) {
        this.utilDao = utilDao;
    }

    public DomainDao getDomainDao() {
        return domainDao;
    }

    @Autowired
    public void setDomainDao(DomainDao domainDao) {
        this.domainDao = domainDao;
    }

    public ServiceDao getServiceDao() {
        return serviceDao;
    }
    
    @Autowired
    public void setServiceDao(ServiceDao serviceDao) {
        this.serviceDao = serviceDao;
    }

    public ConfigurationWindow getConfigurationWindow() {
        return configurationWindow;
    }

    @Autowired
    public void setConfigurationWindow(ConfigurationWindow configurationWindow) {
        this.configurationWindow = configurationWindow;
    }

}
